package com.app.beu.core.renderer;

import com.core.tsm.Component;
import com.core.tsm.Image;
import com.core.tsm.Label;
import com.core.tsm.List;
import com.core.tsm.list.ListCellRenderer;

public class MagicRenderer implements ListCellRenderer {
	private Image[] images;
	Label labelSelected;
	Label labelRender;

	public MagicRenderer(int selectedColor, int unSelectColor, Image[] images) {
//		System.out.println("Magic Renderer INIT");
		this.images = images;
		labelSelected = new Label();
		labelSelected.getSelectedStyle().setPadding(Label.TOP, 0);
		labelSelected.getSelectedStyle().setMargin(Label.TOP, 0);
		labelSelected.getSelectedStyle().setPadding(Label.BOTTOM, 0);
		labelSelected.getSelectedStyle().setMargin(Label.BOTTOM, 0);
		labelSelected.getSelectedStyle().setPadding(Label.LEFT, 0);
		labelSelected.getSelectedStyle().setMargin(Label.LEFT, 0);
		labelSelected.getSelectedStyle().setPadding(Label.RIGHT, 0);
		labelSelected.getSelectedStyle().setMargin(Label.RIGHT, 0);
		labelSelected.getSelectedStyle().setBgColor(selectedColor);
		labelSelected.getSelectedStyle().setBgTransparency(255);
		labelSelected.setFocus(true);

		labelRender = new Label();
		labelRender.getStyle().setPadding(Label.TOP, 0);
		labelRender.getStyle().setMargin(Label.TOP, 0);
		labelRender.getStyle().setPadding(Label.BOTTOM, 0);
		labelRender.getStyle().setMargin(Label.BOTTOM, 0);
		labelRender.getStyle().setPadding(Label.LEFT, 0);
		labelRender.getStyle().setMargin(Label.LEFT, 0);
		labelRender.getStyle().setPadding(Label.RIGHT, 0);
		labelRender.getStyle().setMargin(Label.RIGHT, 0);
		labelRender.getStyle().setBgColor(unSelectColor);
		labelRender.getStyle().setBgTransparency(255);
		labelRender.getStyle().setFgColor(0);
	}

	public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
//		System.out.println("Magic Renderer " + index);
		labelRender.setText(value.toString());
		if (images != null) {
			if (images.length == 1) {
				labelRender.setIcon(images[0]);
			} else {
				labelRender.setIcon(images[index]);
			}
		}
		return labelRender;
	}

	public Component getListFocusComponent(List list) {
		return labelSelected;
	}

	public Image[] getImages() {
		return images;
	}

	public void setImages(Image[] images) {
		this.images = images;
	}

}
